package edu.ccut.saturn.studio.dialog;
//package edu.ccut.saturn.studio.dialog;
//
//import java.util.Arrays;
//import java.util.Map;
//
//import org.eclipse.jface.viewers.ILabelProvider;
//import org.eclipse.swt.SWT;
//import org.eclipse.swt.events.SelectionAdapter;
//import org.eclipse.swt.events.SelectionEvent;
//import org.eclipse.swt.graphics.Point;
//import org.eclipse.swt.graphics.Rectangle;
//import org.eclipse.swt.layout.FormAttachment;
//import org.eclipse.swt.layout.FormData;
//import org.eclipse.swt.layout.FormLayout;
//import org.eclipse.swt.layout.GridData;
//import org.eclipse.swt.widgets.Composite;
//import org.eclipse.swt.widgets.Control;
//import org.eclipse.swt.widgets.Display;
//import org.eclipse.swt.widgets.Event;
//import org.eclipse.swt.widgets.Label;
//import org.eclipse.swt.widgets.Listener;
//import org.eclipse.swt.widgets.Menu;
//import org.eclipse.swt.widgets.MenuItem;
//import org.eclipse.swt.widgets.Shell;
//import org.eclipse.swt.widgets.Text;
//import org.eclipse.swt.widgets.ToolBar;
//import org.eclipse.swt.widgets.ToolItem;
//import org.eclipse.ui.dialogs.AbstractElementListSelectionDialog;
//import org.w3c.dom.Document;
//
//import edu.ccut.saturn.observer.IObserver;
//import edu.ccut.saturn.studio.Activator;
//import edu.ccut.saturn.studio.Images;
//import edu.ccut.saturn.studio.core.util.eclipse.SaturnSWTUtils;
//import edu.ccut.saturn.studio.logic.model.Shape;
//
//public class FilterDialogObserver extends AbstractElementListSelectionDialog {
//
//	protected Object[] fElements;
//
//	protected Shape shape;
//
//	private String[] temp = new String[] { "" };
//
//	private Map<String, Document> map;
//
//	public FilterDialogObserver(Shell parent, Shape shape) {
//		super(parent, new SaturnSWTUtils.SaturnLabelDefaultProvider());
//		this.shape = shape;
//	}
//
//	public FilterDialogObserver(Shell parent, ILabelProvider renderer,
//			Shape shape) {
//		super(parent, renderer);
//		this.shape = shape;
//	}
//
//	protected Point getInitialSize() {
//		return new Point(600, 500);
//	}
//
//	public void setElements(Object[] elements) {
//		fElements = elements;
//	}
//
//	protected void computeResult() {
//		setResult(Arrays.asList(getSelectedElements()));
//	}
//
//	protected Control createDialogArea(Composite parent) {
//		Composite contents = (Composite) super.createDialogArea(parent);
//		createSearch(contents);
//		createFilterText(contents);
//		createFilteredList(contents);
//		createMessageArea(contents);
//		setListElements(temp);
//		setSelection(getInitialElementSelections().toArray());
//
//		return contents;
//	}
//
//	protected Text createJarPathText(Composite parent) {
//
//		Text text = new Text(parent, SWT.BORDER | SWT.READ_ONLY);
//
//		GridData data = new GridData();
//		data.grabExcessVerticalSpace = false;
//		data.grabExcessHorizontalSpace = true;
//		data.horizontalAlignment = GridData.FILL;
//		data.verticalAlignment = GridData.BEGINNING;
//		text.setLayoutData(data);
//		text.setFont(parent.getFont());
//
//		return text;
//	}
//
//	private Composite createSearch(Composite parent) {
//		MenuItem projectMenuItem;
//		MenuItem AllMenuItem;
//		final Composite composite = new Composite(parent, SWT.NONE);
//		final GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, true,
//				false);
//		gd_composite.heightHint = 28;
//		composite.setLayoutData(gd_composite);
//		composite.setLayout(new FormLayout());
//
//		final Label label = new Label(composite, SWT.NONE);
//		final FormData fd_label = new FormData();
//		fd_label.bottom = new FormAttachment(0, 24);
//		fd_label.top = new FormAttachment(16);
//		fd_label.right = new FormAttachment(0, 27);
//		fd_label.left = new FormAttachment(0, 2);
//		label.setLayoutData(fd_label);
//		label.setText("Key");
//
//		final ToolBar toolBar = new ToolBar(composite, SWT.FLAT);
//		final FormData fd_toolBar = new FormData();
//		fd_toolBar.top = new FormAttachment(0);
//		fd_toolBar.right = new FormAttachment(100);
//		toolBar.setLayoutData(fd_toolBar);
//		final ToolItem projectToolItem = new ToolItem(toolBar, SWT.DROP_DOWN);
//		projectToolItem.addSelectionListener(new SelectionAdapter() {
//			public void widgetSelected(final SelectionEvent e) {
//				if (e.detail == 0) {
//					setListElements(fElements);
//				}
//			}
//		});
//
//		projectToolItem.setImage(Activator.getImage(Images.AMPLIFY_PLUS));
//		final Menu menu = new Menu(toolBar);
//		addDropDown(projectToolItem, menu);
//		projectMenuItem = new MenuItem(menu, SWT.NONE);
//		projectMenuItem.addSelectionListener(new SelectionAdapter() {
//			public void widgetSelected(final SelectionEvent e) {
//				setListElements(map.keySet().toArray(new String[0]));
//			}
//		});
//		projectMenuItem.setText("Search Current Project");
//		AllMenuItem = new MenuItem(menu, SWT.NONE);
//		AllMenuItem.addSelectionListener(new SelectionAdapter() {
//			public void widgetSelected(final SelectionEvent e) {
//				fElements = temp;
//				setListElements(fElements);
//				startThreadWordspace();
//			}
//		});
//		AllMenuItem.setText("Search The Workspace");
//		startThreadProject();
//		return composite;
//	}
//
//	private static void addDropDown(final ToolItem item, final Menu menu) {
//		item.addListener(SWT.Selection, new Listener() {
//			public void handleEvent(Event event) {
//				if (event.detail == SWT.ARROW) {
//					Rectangle rect = item.getBounds();
//					Point pt = new Point(rect.x, rect.y + rect.height);
//					pt = item.getParent().toDisplay(pt);
//					menu.setLocation(pt.x, pt.y);
//					menu.setVisible(true);
//				}
//			}
//		});
//	}
//
//	protected void startThreadProject() {
//		new Thread(new Runnable() {
//			public void run() {
//				if (shape != null) {
//					shape.keyMapInProject(new ObserverImp());
//				}
//			}
//		}).start();
//	}
//
//	protected void startThreadWordspace() {
//		new Thread(new Runnable() {
//			public void run() {
//				if (shape != null) {
//					shape.keyMapInWorkspace(new ObserverImp());
//				}
//			}
//		}).start();
//	}
//
//	protected void configureShell(Shell newShell) {
//		super.configureShell(newShell);
//		newShell.setImage(Activator.getImage(Images.SATURN_ICONS_SMALLNAME));
//	}
//
//	public Map<String, Document> getMap() {
//		return map;
//	}
//
//	public void setMap(Map<String, Document> map) {
//		this.map = map;
//	}
//
//	class ObserverImp implements IObserver {
//		public synchronized void update(final Map<String, Document> files) {
//			Display.getDefault().asyncExec(new Runnable() {
//				public void run() {
//					for (String value : files.keySet()) {
//						Document document = files.get(value);
//						map.put(value, document);
//					}
//					setListElements(map.keySet().toArray(new String[0]));
//				}
//			});
//		}
//	}
//}
